{* Smarty *}
{*
 *  This file is part of Urd.
 *
 *  Urd is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *  Urd is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program. See the file "COPYING". If it does not
 *  exist, see <http://www.gnu.org/licenses/>.
 *
 * $LastChangedDate: 2008-07-15 15:42:06 +0200 (Tue, 15 Jul 2008) $
 * $Rev: 1296 $
 * $Author: gavinspearhead $
 * $Id: browse.tpl 1296 2008-07-15 13:42:06Z gavinspearhead $
 *}
{include file="head.tpl" title=$title rssurl=$rssurl}

{* These icon images are a copy of the code in formatsetname.tpl *}
{* Smarty doesn't allow you to 'include' variables from another file... *}
{* Icon images: (Global variable ish) *}
{assign var="btmovie" value="<img class=\"binicon\" src=\"$IMGDIR/bin_movie.png\" alt=\"\"/>"}
{assign var="btmusic" value="<img class=\"binicon\" src=\"$IMGDIR/bin_music.png\" alt=\"\"/>"}
{assign var="btimage" value="<img class=\"binicon\" src=\"$IMGDIR/bin_image.png\" alt=\"\"/>"}
{assign var="btsoftw" value="<img class=\"binicon\" src=\"$IMGDIR/bin_software.png\" alt=\"\"/>"}
{assign var="bttv"    value="<img class=\"binicon\" src=\"$IMGDIR/bin_series.png\" alt=\"\"/>"}
{assign var="btdocu"  value="<img class=\"binicon\" src=\"$IMGDIR/bin_documentary.png\" alt=\"\"/>"}
{assign var="btgame"  value="<img class=\"binicon\" src=\"$IMGDIR/bin_games.png\" alt=\"\"/>"}
{assign var="btebook" value="<img class=\"binicon\" src=\"$IMGDIR/bin_ebook.png\" alt=\"\"/>"}

<span class="Message" id="message_bar"></span>
{* Search form *}
<form id="searchform" action="" method="get">
<div>
<table class="rss" width="100%">
<tr>
<td>
<div id="adv_search_button" class="floatleft iconsize dynimgplus noborder buttonlike" onclick="javascript:fold_adv_search();" {popup text=$LN_advanced_search}>
</div>&nbsp;


	{$LN_browse_searchsets}:
	<input type="hidden" name="order" value="{$order}" id="searchorder"/>
{if $prev_group != ''}
    <input type="button" value="<" {popup text=$LN_previous } onclick='javascript:do_submit_group("searchform", {$prev_group})'/>
{/if}
	<select name="groupID" class="search" id="select_groupID" >
    <option value="">{$LN_browse_allgroups}</option>
	{section name=x loop=$subscribedgroups}
		<option {if $subscribedgroups[x].id == $groupID}selected="selected"{/if} value="{$subscribedgroups[x].id}">{$subscribedgroups[x].shortname|escape:htmlall} ({$subscribedgroups[x].article_count})</option>
	{/section}
	</select>
{if $next_group != ''}
    <input type="button" value=">" {popup text=$LN_next } onclick='javascript:do_submit_group("searchform", {$next_group})'/>
{/if}
    <select name="flag" class="search">
		<option {if $flag == ''} selected="selected" {/if} value="">{$LN_browse_allsets}</option>
		<option {if $flag == 'interesting'} selected="selected" {/if} value="interesting">{$LN_browse_interesting}</option>
		<option {if $flag == 'read'} selected="selected" {/if} value="read">{$LN_browse_downloaded}</option>
		<option {if $flag == 'nzb'} selected="selected" {/if} value="nzb">{$LN_browse_nzb}</option>
		<option {if $flag == 'kill'} selected="selected" {/if} value="kill">{$LN_browse_killed}</option>
	</select>
 
	<input type="text" name="search" size="30" class="search" value="{if $search == ''}<{$LN_search}>{else}{$search|escape:htmlall}{/if}" onfocus="if (this.value=='<{$LN_search}>') this.value='';"/>
	<!--input type="hidden" value="" name="maxage"/-->
		<input type="submit" value="{$LN_search}" class="submit" onclick='javascript:do_submit("searchform");'/>
    &nbsp; &nbsp;
	<input type="button" value="{$LN_reset}" class="submit" onclick='javascript:clear_form("searchform");'/>
    <img src="{$IMGDIR}/icon_mail.png" class="buttonlike" alt="" onclick="javascript:show_post_message('{$groupID}');" {popup text=$LN_post_message } />
</td>
<td class="rss2">
<div> <table class="rss"><tr><td class="rssleft"><a href="{$rssurl}" class="rss">RSS</a></td><td class="rssright">2.0</td></tr></table> </div>
</td>
</tr>
<tr class="adv_search {if $show_advanced_search eq 0}hidden{/if}" id="adv_search">
<td><div>
<table>
<tr><td>{$LN_minsetsize}:</td><td><input type="text" name="minsetsize" size="10" value="{$minsetsize}"/></td> <td>{$LN_maxsetsize}:</td><td><input type="text" name="maxsetsize" size="10" value="{$maxsetsize}"/></td>
<td>{$LN_minage}:</td><td><input type="text" name="minage" size="10" value="{$minage}"/></td> <td>{$LN_maxage}:</td><td><input type="text" name="maxage" size="10" value="{$maxage}"/></td></tr>
<tr><td>{$LN_minrating}:</td><td><input type="text" name="minrating" size="10" value="{$minrating}"/></td> <td>{$LN_maxrating}:</td><td><input type="text" name="maxrating" size="10" value="{$maxrating}"/></td>
<td>{$LN_mincomplete}:</td><td><input type="text" name="mincomplete" size="10" value="{$mincomplete}"/></td> <td>{$LN_maxcomplete}:</td><td><input type="text" name="maxcomplete" size="10" value="{$maxcomplete}"/></td></tr>
</table></div>
</td></tr>

</table>
</div>
</form>
{if $message != ""}<span class="Message">{$message}</span>
<br/>
{/if}

{*
{if $numaddedsets > 0}
<table class="addedsets">
<tr><td class="ashead">{$LN_browse_allsets}:</td></tr>
<tr><td class="asmain">
{section name=x loop=$addedsets}
{$addedsets[x].subject}<br/>
{/section}
</td></tr>
</table>
<br/>
{/if}
*}

{* Show added sets: *}

{capture assign="leftbuttons"}
<div id="basketbuttondiv" class="hidden">
<table class="basketbuttons">
<tr><td>
<input type="image" value="Download" src="{$IMGDIR}/downloadarticles.png" class="submitimage" alt="{$LN_browse_download}" {popup text=$LN_browse_download } name="urddownload" onclick="javascript:Whichbutton('urddownload');"/></td>
<td><input type="image" value="Save NZB file" src="{$IMGDIR}/getnzb.png" class="submitimage" alt="{$LN_browse_savenzb}" {popup text=$LN_browse_savenzb } name="getnzb" onclick="javascript:Whichbutton('getnzb');"/></td>
<td><input type="image" value="Merge sets"    src="{$IMGDIR}/mergesets.png" class="submitimage" alt="{$LN_browse_mergesets}" {popup text=$LN_browse_mergesets } name="mergesets" onclick="javascript:Whichbutton('mergesets');"/></td>
<td><input type="image" value="Empty list"    src="{$IMGDIR}/clearlist.png" class="submitimage" alt="{$LN_browse_emptylist}" {popup text=$LN_browse_emptylist } name="clearnzb" onclick="javascript:Whichbutton('clearnzb');"/></td>
<td>{$LN_browse_schedule_at}: <input name="timestamp" type="text" value="" size="20"/>
</td></tr>
</table>
</div>
{/capture}

{* Display the content: *}
<form action="" method="post" id="setform">
<table width="100%" class="browsetoptable">
<tr><td colspan="3" class="minimalistic"><div id="basketdiv"></div></td></tr>
<tr><td class="leftbut minimalistic">{$leftbuttons}</td><td class="midbut minimalistic"></td><td class="rightbut minimalistic"></td></tr>
</table>

{capture assign=topskipper}{strip}
<table class="pageskip">
<tr>
{* Determine the start/stop page: *}
{assign var="startpage" value="`$currentpage-10`"}
{if $startpage < 1} {assign var="startpage" value="1"} {/if}
{assign var="stoppage" value="`$startpage+20`"}
{if $stoppage > $lastpage} {assign var="stoppage" value=$lastpage} {/if}
{assign var="startpage" value="`$stoppage-20`"}
{if $startpage < 1} {assign var="startpage" value="1"} {/if}

{section name=x loop=$pages}
{* Always do first *}
{if $pages[x].number == 1}
	<td class="ps_{$pages[x].distance}" onmouseover="this.style.color='white'; this.style.cursor='pointer'" onmouseout="this.style.color='black';" onclick="document.location='{$pages[x].url|escape:htmlall}'">
	{$pages[x].number}
	</td>
	{if $startpage > 1}
		<td class="spacer">&nbsp;</td>
	{/if}
{* Always do last *}
{elseif $pages[x].number == $lastpage}
	{if $stoppage < $lastpage}
		<td class="spacer">&nbsp;</td>
	{/if}
	<td class="ps_{$pages[x].distance}" onmouseover="this.style.color='white'; this.style.cursor='pointer'" onmouseout="this.style.color='black';" onclick="document.location='{$pages[x].url|escape:htmlall}'">
	{$pages[x].number}
	</td>
{* Only do the surrounding ones *}
{elseif $pages[x].number >= $startpage AND $pages[x].number <= $stoppage}
	<td class="ps_{$pages[x].distance}" onmouseover="this.style.color='white'; this.style.cursor='pointer'" onmouseout="this.style.color='black';" onclick="document.location='{$pages[x].url|escape:htmlall}'">
	{$pages[x].number}
	</td>
{/if}
{/section}
</tr>
</table>{/strip}
{/capture}

{* Making a 'top' and a 'bottom' skipper: *}
{capture assign=bottomskipper}{strip}
<table class="pageskipbottom">
<tr>
{* Determine the start/stop page: *}
{assign var="startpage" value="`$currentpage-10`"}
{if $startpage < 1} {assign var="startpage" value="1"} {/if}
{assign var="stoppage" value="`$startpage+20`"}
{if $stoppage > $lastpage} {assign var="stoppage" value=$lastpage} {/if}
{assign var="startpage" value="`$stoppage-20`"}
{if $startpage < 1} {assign var="startpage" value="1"} {/if}

{section name=x loop=$pages}
{* Always do first *}
{if $pages[x].number == 1}
	<td class="psb_{$pages[x].distance}" onmouseover="this.style.color='white'; this.style.cursor='pointer'" onmouseout="this.style.color='black';" onclick="document.location='{$pages[x].url|escape:htmlall}'">
	{$pages[x].number}
	</td>
	{if $startpage > 1} <td class="spacer">&nbsp;</td> {/if}
{* Always do last *}
{elseif $pages[x].number == $lastpage}
	{if $stoppage < $lastpage} <td class="spacer">&nbsp;</td> {/if}
	<td class="psb_{$pages[x].distance}" onmouseover="this.style.color='white'; this.style.cursor='pointer'" onmouseout="this.style.color='black';" onclick="document.location='{$pages[x].url|escape:htmlall}'">
	{$pages[x].number}
	</td>
{* Only do the surrounding ones *}
{elseif $pages[x].number >= $startpage AND $pages[x].number <= $stoppage}
	<td class="psb_{$pages[x].distance}" onmouseover="this.style.color='white'; this.style.cursor='pointer'" onmouseout="this.style.color='black';" onclick="document.location='{$pages[x].url|escape:htmlall}'">
	{$pages[x].number}
	</td>
{/if}
{/section}
</tr>
</table>{/strip}
{/capture}

{capture assign=unmark_int_all}{strip}
<input type="hidden" name="groupid" value="{$groupID}"/>
{if $isadmin}
<input type="image" value="submit" class="submitimage" name="delete_all" src="{$IMGDIR}/icon_purge.png" onclick="javascript:Whichbutton('wipe_all')" alt="{$LN_browse_deleteset}" height="16" width="16" {popup text=$LN_browse_deleteset}/>&nbsp;
{/if}
{if $killflag}
<input type="image" value="submit" class="submitimage" alt="unmark kill" name="unmark_kill" onclick="javascript:Whichbutton('unmark_kill_all');" src="{$IMGDIR}/icon_cancel.png" {popup text=$LN_browse_resurrectset}  />
{else}
<input type="image" value="submit" class="submitimage" alt="mark kill" name="mark_kill" onclick="javascript:Whichbutton('mark_kill_all');" src="{$IMGDIR}/icon_delete.png" {popup text=$LN_browse_removeset } />
{/if}&nbsp;
<input type="image" value="submit" class="submitimage" alt="unmark interesting" name="unmark_int" onclick="javascript:Whichbutton('unmark_int_all');" src="{$IMGDIR}/icon_sad.png" {popup text=$LN_browse_toggleint }  />
{/strip}
{/capture}

{* We need this stuff to remember any the search options *}
<div>
{section name=y loop=$allsets}
<input type="hidden" name="set_ids[]" value="{$allsets[y].sid}"/>
{/section}
<input type="hidden" name="offset" value="{$offset}"/>
<input type="hidden" name="challenge" id="challenge" value="{$challenge}"/>
<input type="hidden" name="groupID" value="{$groupID}"/>
<input type="hidden" name="search" value="{$search|escape:htmlall}"/>
<input type="hidden" name="retention" value="{$maxage}"/>
<input type="hidden" name="maxage" value="{$maxage}"/>
<input type="hidden" name="minxage" value="{$minage}"/>
<input type="hidden" name="maxsetsize" value="{$maxsetsize}"/>
<input type="hidden" name="minxsetsize" value="{$minsetsize}"/>
<input type="hidden" name="order" value="{$order}"/>
<input type="hidden" name="dlname" value=""/>
<input type="hidden" name="whichbutton" value="" id="whichbutton"/>
<input type="hidden" name="previewBinID" value="" id="previewBinID"/>
<input type="hidden" name="previewGroupID" value="" id="previewGroupID"/>
<input type="hidden" name="lastdivid" id="lastdivid" value=""/>
<input type="hidden" name="curScrollVal" id="curScrollVal" value="" />
</div>
</form>

{* And display it here and at the bottom: *}
{$topskipper}

<table class="articles">
<tr class="head">
<th>&nbsp;</th>
<th>&nbsp;</th>
<th class="fixwidth1 cursor_hand head" onclick="javascript:SubmitSearchWithOrder('complete');">{$LN_browse_percent}</th>
<th class="head cursor_hand" onclick="javascript:SubmitSearchWithOrder('better_subject');">{$LN_browse_subject}</th>
<th class="fixwidth1 cursor_hand head right" onclick="javascript:SubmitSearchWithOrder('rating');"><img src="{$IMGDIR}/icon_follow.png" class="buttonlike noborder" alt=""/></th>
<th class="fixwidth2 cursor_hand head right" onclick="javascript:SubmitSearchWithOrder('date');">{$LN_browse_age}</th>
<th class="fixwidth3 cursor_hand head right" onclick="javascript:SubmitSearchWithOrder('size');">{$LN_size}</th>
<th class="fixwidth4 right">{$unmark_int_all}</th>
</tr>

{* Display the bunch: *}
{section name=x loop=$allsets}

{capture assign=smallbuttons}	
{if !$allsets[x].added}
<input type="hidden" name="setdata[]" id="set_{$allsets[x].sid}" value=""/>
<img id="big_{$allsets[x].sid}" src="{$IMGDIR}/icon_plus.png" onclick="javascript:SelectSet('{$allsets[x].sid}', 'group', event);return false;" class="buttonlike" alt="+" height="16" width="16"/>
{else}
<input type="hidden" name="setdata[]" id="set_{$allsets[x].sid}" value="x"/>
<img id="big_{$allsets[x].sid}" src="{$IMGDIR}/icon_minus.png" onclick="javascript:SelectSet('{$allsets[x].sid}', 'group', event)" class="buttonlike" alt="-" height="16" width="16"/>
{/if}
{/capture}

{capture assign=complete}
{$IMGDIR}/{$sign}
{/capture}

{* Store flags to be used in class definition: *}
{assign var='read' value=''}
{assign var='nzb' value=''}
{assign var='interesting' value=''}
{assign var='interestingimg' value="$IMGDIR/icon_smile.png"}
{if $allsets[x].read == 1}{assign var='read' value='markedread'}{/if}
{if $allsets[x].nzb == 1}{assign var='nzb' value='markednzb'}{/if}
{if $allsets[x].interesting == 1}{assign var='interesting' value='interesting'}{/if}
{if $allsets[x].interesting == 1}{assign var='interestingimg' value="$IMGDIR/icon_sad.png"}{/if}

{assign var='complete' value="$IMGDIR/light_yellow.png"}
{assign var='completion' value=$allsets[x].complete}
{assign var='completion' value="$completion%"}

{if $allsets[x].complete < 120}{assign var='complete' value="$IMGDIR/light_green.png"}{/if}
{if $allsets[x].complete < 100}{assign var='complete' value="$IMGDIR/light_orange.png"}{/if}
{if $allsets[x].complete < 90}{assign var='complete' value="$IMGDIR/light_red.png"}{/if}
{if $allsets[x].complete == -1}{assign var='complete' value="$IMGDIR/light_off.png"}{assign var='completion' value='Completion unknown'}{/if}

{* Remember this is a copy of formatsetname.tpl; included here for performance reasons (beats 100's of includes) (I think) *}
{capture assign=setdesc}{$allsets[x].name|truncate:$maxstrlen:'...':true|escape:htmlall}{/capture}
{capture assign=setdesc}{$setdesc|replace:':_img_movie:':$btmovie}{/capture}
{capture assign=setdesc}{$setdesc|replace:':_img_album:':$btmusic}{/capture}
{capture assign=setdesc}{$setdesc|replace:':_img_image:':$btimage}{/capture}
{capture assign=setdesc}{$setdesc|replace:':_img_software:':$btsoftw}{/capture}
{capture assign=setdesc}{$setdesc|replace:':_img_series:':$bttv}{/capture}
{capture assign=setdesc}{$setdesc|replace:':_img_tvshow:':$bttv}{/capture}
{capture assign=setdesc}{$setdesc|replace:':_img_documentary:':$btdocu}{/capture}
{capture assign=setdesc}{$setdesc|replace:':_img_ebook:':$btebook}{/capture}
{capture assign=setdesc}{$setdesc|replace:':_img_game:':$btgame}{/capture}

{* Ok now it's time to put it all together: *}	
<tr class="content{$added} even {$interesting} {$read} {$nzb}" id="base_row_{$allsets[x].sid}" 
	onmouseover="javascript:ToggleClass(this,'highlight2')" 
	onmouseout="javascript:ToggleClass(this,'highlight2')">
	<td class="fixwidth1">{$allsets[x].number}</td>
	<td class="setbuttons">{$smallbuttons}</td>
	<td class="fixwidth1"><img src="{$complete}" alt="{$completion}" {popup text="$completion" } height="16" width="16"/></td>
	<td onmouseup="javascript:theevent = CloneObject(event); setTimeout('ShowQuickMenu(\'browse\',\'{$allsets[x].sid}\', {$USERSETTYPE_GROUP},theevent)',200);" id="td_set_{$allsets[x].sid}">{$setdesc}
</td>
{assign var='rating' value=$allsets[x].rating}
{assign var='imdbpic' value="icon_$rating.png"}
{if $rating == ""}{assign var='imdbpic' value="icon_follow.png"}{/if}
<td  class="fixwidth1">{if $allsets[x].imdblink neq ''}<a href="{$allsets[x].imdblink|escape}">
				<img src="{$IMGDIR}/{$imdbpic|escape}" class="buttonlink noborder" alt="link" height="16" width="16"/>
				</a>
			{else}{if $allsets[x].rating neq 0}
				<img src="{$IMGDIR}/{$imdbpic|escape}" class="buttonlink noborder" alt="link" height="16" width="16"/>
				{/if}
			{/if}</td>

	<td class="fixwidth2 {if $allsets[x].new_set neq 0}newset{/if}">{$allsets[x].age}</td>
	<td class="fixwidth3">{$allsets[x].size}</td>
	<td class="fixwidth4">
    {if $isadmin}
		<img src="{$IMGDIR}/icon_purge.png" onclick="javascript:markRead('{$allsets[x].sid}', 'wipe', {$USERSETTYPE_GROUP})" alt="{$LN_browse_deleteset}" class="buttonlike" {popup text=$LN_browse_deleteset} height="16" width="16" />
    {/if}
	{if $killflag}
		<img src="{$IMGDIR}/icon_cancel.png" onclick="javascript:markRead('{$allsets[x].sid}','unhide', {$USERSETTYPE_GROUP})" alt="{$LN_browse_resurrectset}" class="buttonlike" {popup text=$LN_browse_resurrectset} height="16" width="16" />
	{else}
		<img src="{$IMGDIR}/icon_delete.png" onclick="javascript:markRead('{$allsets[x].sid}','hide', {$USERSETTYPE_GROUP})" alt="{$LN_browse_removeset}" class="buttonlike" {popup text=$LN_browse_removeset } height="16" width="16" />
	{/if}
	<img src="{$interestingimg}" onclick="javascript:markRead('{$allsets[x].sid}','interesting', {$USERSETTYPE_GROUP})" class="buttonlike" alt="{$LN_browse_toggleint}" {popup text=$LN_browse_toggleint } id="intimg_{$allsets[x].sid}" height="16" width="16"/>
	</td>
</tr>
{/section}

{* Last bit: *}
</table>{$bottomskipper}

{* Load basket: *}
<script type="text/javascript">
UpdateBasketDisplay();
</script>

<div id="postmessagediv" class="postmessageoff">
</div>

{* Store button urls for javascript: *}
<input type="hidden" id="buttonplus" value="{$IMGDIR}/icon_plus.png"/>
<input type="hidden" id="buttonminus" value="{$IMGDIR}/icon_minus.png"/>
<input type="hidden" id="buttonint" value="{$IMGDIR}/icon_smile.png"/>
<input type="hidden" id="buttonunint" value="{$IMGDIR}/icon_sad.png"/>

{include file="foot.tpl"}
